﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using XbsWebAPI.Application;
using XbsWebAPI.Application.CheckInOut;
using XbsWebAPI.Application.CheckInOut.Dtos;
using XbsWebAPI.Application.QueryModel;
using XbsWebAPI.EntityFrameworkCore.Entities;

namespace XbsWebAPI.MainHost.Controllers
{
    [ApiController]
    [Route("api/xbs_v1/[controller]")]
    public class CheckOutController : Controller
    {
        private readonly ICheckOutAppService _checkOutAppService;

        public CheckOutController(ICheckOutAppService checkOutAppService)
        {
            _checkOutAppService = checkOutAppService;
        }

        ///<summary>
        ///办理退房
        /// </summary>
        [HttpGet, Route("[action]")]
        public async Task<ResultDto<string>> AddCheckOut(Guid? orderId)
        {
            var result = await _checkOutAppService.AddCheckOutAsync(orderId);
            return result;
        }

        /// <summary>
        /// 分页查询退房
        /// </summary>
        /// <param name="name">营位名称</param>
        /// <param name="pageNumber">第几页，默认1</param>
        /// <param name="pageSize">每页多少条，默认10</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<PageListDto<ListCheckOutDto>> FindCheckOutPagedList(string name, int? pageNumber, int? pageSize)
        {
            QueryCheckOut query = new QueryCheckOut
            {
                Name = name,
                PageNumber = pageNumber,
                PageSize = pageSize
            };
            var result = _checkOutAppService.GetPagedList(query);

            return result;
        }

        ///<summary>
        ///办理退房（测试加数据用）
        /// </summary>
        [HttpGet, Route("[action]")]
        public async Task<ResultDto<string>> AddCheckOutTest()
        {
            var orderNumbers = new[] { "LJ001002", "LJ001003", "LJ001004", "LJ001005", "LJ001006", "LJ001007", "LJ001008", "LJ001009", "LJ001010", "LJ001011" };
            var BookingPersonses = new[] { "张三、李四", "李四", "王五、李四", "张三", "啊哈、李", "唔唔唔", "好的、李四", "李四、呜呜", "王五、好的", "加戏、嗯额" };
            var BookingPhoneNumberses = new[] { "13623562145", "13625623141", "13623623142", "13623623143", "13623563149", "13235623145", "13245623122", "13245623133", "13245623100", "" };

            for (int i = 0; i < 10; i++)
            {
                CheckOut model = new CheckOut();
                model.Id = Guid.NewGuid();
                model.OrderId = Guid.NewGuid();
                model.RoomId = Guid.NewGuid();
                model.OrderNumber = orderNumbers[i];
                model.RoomName = "垃圾数据房间";
                model.BookingPersons = BookingPersonses[i];
                model.BookingPhoneNumbers = BookingPhoneNumberses[i];
                model.Remark = "";
                await _checkOutAppService.AddCheckOutTest(model);
            }

            
            return null;
        }
    }
}
